/**
 * KAYO APPLIANCE CHAINS.
 * Copyright (c) 2016-2016 All Rights Reserved.
 */
package com.leku.video.controller.kv;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.leku.commons.util.StringUtil;
import com.leku.video.base.BaseController;
import com.leku.video.constants.ResultEnum;
import com.leku.video.dto.request.BaseReqDto;
import com.leku.video.dto.result.ResultDto;
import com.leku.video.dto.result.home.CenterResDto;
import com.leku.video.service.home.HomeService;
import com.leku.video.util.ServletUtil;

/**
 * 
 * 功能描述:首页服务
 *
 * @author Ranphy
 * @created 2018年9月20日
 * @version 1.0.0
 */
@Controller
public class HomeController extends BaseController {

	private static final Logger LOG = LoggerFactory.getLogger(HomeController.class);

	@Autowired
	private HomeService homeService;

	/**
	 * 
	 * 功能描述: 审核开关
	 *
	 * @param request
	 * @param response
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("/video/kv")
	@ResponseBody
	public void videoKv(HttpServletRequest request, HttpServletResponse response) {

		ResultDto<CenterResDto> resultDto = new ResultDto<CenterResDto>();

		BaseReqDto reqDto = new BaseReqDto();
		preBaseDto(reqDto, request);

		// 参数校验不通过
		if (!checkBaseParam(reqDto) || StringUtil.isEmpty(reqDto.getOs())) {
			resultDto.setRet(ResultEnum.PARAMERROR.getResCode());
			resultDto.setMsg(ResultEnum.PARAMERROR.getResMsg());
			writeReponse(request, response, resultDto);
			return;
		}

		try {
			resultDto.setData(homeService.findVideoKv(reqDto));
			resultDto.setRet(ResultEnum.SUCCESS.getResCode());
			resultDto.setMsg(ResultEnum.SUCCESS.getResMsg());
		} catch (Exception e) {
			resultDto.setRet(ResultEnum.SYSERROR.getResCode());
			resultDto.setMsg(ResultEnum.SYSERROR.getResMsg());
			LOG.error("获取视频解析插件系统异常," + getAppInfo(reqDto), e);
		}

		writeReponse(request, response, resultDto);
	}

}
